home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 151 / aimtutor.doc < prev    next >
Encoding:
Text File  |  1988-10-20  |  44.7 KB  |  949 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.                     A I M   T U T O R I A L
  13.  
  14.  
  15.                               by
  16.  
  17.  
  18.                  Tom Hoeksma and Ad Herweijer
  19.  
  20.  
  21.  
  22.                 Delft University of Technology
  23.                   Faculty of Applied Physics
  24.                    Pattern Recognition Group
  25.                          Lorentzweg 1
  26.                         2628 CJ  DELFT
  27.                         the Netherlands
  28. Introduction
  29.  
  30. The  image processing software package AIM (Atari Image  Manager) 
  31. has  been  developed at Delft University of Technology  by  Frans 
  32. Groen  (the 'image processor') and was adapted for the  Atari  ST 
  33. computer  in cooperation with Robert de Vries (the  GEM  program⑨
  34. mer). Both were members of the Signal-/System-techniques Group in 
  35. the  Faculty of Applied Physics,  Frans as a senior staff  member 
  36. and Robert as a graduate student. Recently, Frans changed jobs to 
  37. become  professor  of Applied Informatics in  the  University  of 
  38. Amsterdam.
  39.  
  40. AIM  is designed to be an entry level 'appetizer' for the art  of 
  41. image   processing.   It  gives  the  interested   layperson   an 
  42. opportunity   to  acquaint  himself  with  the   techniques   and 
  43. terminology  used  in  this   dynamic  field.   The   experiments 
  44. described  may  be  regarded  as a lower bound  of  what  can  be 
  45. accomplished  with  AIM,  the upper bound being  limited  by  the 
  46. user's imagination only. 
  47.  
  48. This  tutorial is not a full course on digital image  processing. 
  49. Such courses are frequently organized by the Pattern  Recognition 
  50. Group.  For course information,  please contact the Secretary  of 
  51. the  Pattern  Recognition  Group,  Faculty  of  Applied  Physics, 
  52. Lorentzweg 1, 2628 CJ  Delft, the Netherlands, Phone 015-781416.
  53.  
  54. Note  that the operations used in the examples and demos cover  a 
  55. minor part of AIM's capabilities only.  A comprehensive  descrip⑨
  56. tion  of all the operations available is given in a  file  called 
  57. AIMANUAL.DOC.  Like this tutorial it is contained in a compressed 
  58. file (DOCS_IMS.ARC), which can be found in the folder COMPRESS on 
  59. the distribution disk (together with a decompressing program).
  60.  
  61. Image processing is not particularly difficult;  many people will 
  62. have   had  their  first  image  processing  experience  in   the 
  63. photographic darkroom.  Note,  however, that AIM, being dedicated 
  64. to  digital image processing,  requires some basic  knowledge  of 
  65. digital systems.  So those of you who until now have successfully 
  66. avoided  learning  about  bits,  bytes  and  binary  numbers,  be 
  67. prepared to face the unavoidable!  The 15 minutes or so spent  on 
  68. reading about these concepts will be richly rewarded by a  better 
  69. understanding of AIM's operations,  if not by the deep admiration 
  70. of your environment for the newly acquired vocabulary.
  71.  
  72. AIM is a result of many years of research and development in  the 
  73. Pattern Recognition Group.  Many of the image processing routines 
  74. were contributed by (a.o.) Gert van Antwerpen,  Frans Groen, Piet 
  75. Verbeek,  Ben  Verwer,  Lucas  van Vliet  and  Igor  Weber.  This 
  76. introduction was written (if not compiled from existing texts) by 
  77. Tom Hoeksma and Ad Herweijer.
  78.  
  79. Previous versions of AIM have already extensively penetrated  the 
  80. Atari ST community.  However,  as the documentation supplied with 
  81. those  first  public  domain versions  was  rather  limited,  the 
  82. exploration  of  the software has been a mere  'image  processing 
  83. adventure'  to most of the 'early birds'.  The authors hope  that 
  84. this introduction,  together with the related examples and  demos 
  85. included  on the disk,  will enable all prospective users  (early 
  86. birds and newcomers alike) to better understand what  was,  resp. 
  87. is going on.
  88.  
  89. Feedback  plays an important role in the effective use  of  image 
  90. processing  as well as in  software  development.  Therefore,  we 
  91. invite you to send your eventual comments and suggestions to:
  92.  
  93.     Prof. dr. ir. F.C.A. Groen
  94.      c/o Delft University of Technology
  95.     Faculty of Applied Physics
  96.      Pattern Recognition Group
  97.     Lorentzweg 1, 2628 CJ  DELFT
  98.      the Netherlands
  99.  
  100.  
  101.  
  102. WHAT CAN WE EXPECT OF IMAGE PROCESSING?
  103.  
  104. Maybe  you  have  already had some experience with  AIM  or  seen 
  105. somebody  else work with it.  You may have  wondered,  then,  how 
  106. image  processing could make features appear in the display  that 
  107. weren't  there  before  the operation.  Text that  at  first  was 
  108. unreadable,  suddenly could be read easily;  freckles in a girl's 
  109. face,  that  didn't show in the original display,  could (to  her 
  110. distress!) be counted after some appropriate keystrokes. You were 
  111. perhaps convinced to have acquired a little magician,  hidden  in 
  112. that tiny floppy disk.
  113.  
  114. Be warned, however! Image processing can never reproduce features 
  115. of  the  original image,  that somehow have  been  lost.  So,  be 
  116. prepared  for  surprises,   but  don't  expect  miracles!   Image 
  117. processing  can  enhance  particular details  in  an  image,  but 
  118. usually other details will have to be sacrificed.
  119.  
  120. If 'A picture is worth a thousand words', image processing allows 
  121. you  to  arrange  those  words to make  the  picture  reveal  its 
  122. (secret) 'stories'.  But remember:  one picture's thousand  words 
  123. are  different  from  another's.  Every story  will  inherit  the 
  124. characteristics of the picture it was extracted from.  The art of 
  125. image  processing  is:  to make the picture tell  the  one  story 
  126. that's useful to you.
  127.  
  128.  
  129.  
  130. STAGES IN AN IMAGE PROCESSING APPLICATION
  131.  
  132. In  almost  every image processing application we  can  recognize 
  133. some stages, that eventually lead to the final result: recording, 
  134. preprocessing,  segmentation, postprocessing, analysis and inter⑨
  135. pretation. 
  136.  
  137. Probably  the  most  important  stage is  the  recording  of  the 
  138. original picture.  As stated above, information that gets lost in 
  139. the recording process can never be recovered. For the recording a 
  140. video-camera  is  required,  capable  of  converting  the  light, 
  141. reflected  from the object,  into an electrical  signal.  As  the 
  142. video signal cannot be read directly by the computer, this signal 
  143. must be sampled and digitized and the digital information must be 
  144. transferred in an orderly manner to the computer's  memory.  This 
  145. is  done  by  a special piece of  hardware,  a  so-called  'frame 
  146. grabber'.  Various frame grabbers are available for the Atari ST. 
  147. In  the  Pattern  Recognition Group monochrome  and  color  frame 
  148. grabbers  have  been  developed  that  eventually  will  be  made 
  149. commercially available.
  150.  
  151. After  the  image  is  stored in the computer  it  must  be  pre⑨
  152. processed.   Here  the  user  tries  to  enhance  or  filter  out 
  153. particular   wanted   resp.   unwanted   features,   to   satisfy 
  154. requirements of further analysis.  Examples of preprocessing  are 
  155. the  correction  for  changing  grey  values  in  the  background 
  156. (shading),  suppressing  noise,  determination  of edges  in  the 
  157. image, etc.
  158.  
  159. In order to be able to determine properties of single objects  in 
  160. the image, these objects must first be made detectable. If a grey 
  161. value  image  contains  dark  objects  on  a  light   background, 
  162. segmentation  can,  for instance,  result in a binary image  with 
  163. white objects in a black background.
  164.  
  165. Postprocessing  can  improve  the  result  of  the  segmentation. 
  166. Examples  are  the morfological  (binary)  operations.  Holes  in 
  167. objects can be closed, edges peeled off, etc.
  168.  
  169. In  the  analysis stage,  measurements can be  performed  on  the 
  170. segmented objects. Examples: area, perimeter, curvature.
  171.  
  172. In  the interpretation stage the results of the measurements  are 
  173. evaluated.
  174.  
  175. An 'intelligent robot' in a factory,  that has to make a decision 
  176. on  whether he 'sees' a nut or a bolt,  must be programmed to  go 
  177. through  all  stages mentioned here.  Programming  such  a  robot 
  178. requires  much intuition on how computers 'think'.  An  important 
  179. requirement for the programmer is to be able to forget the way he 
  180. would  do  the job himself!  He must belong to the new  breed  of 
  181. 'computer psychologists'.
  182.  
  183.  
  184.  
  185. SOME TERMINOLOGY USED IN IMAGE PROCESSING
  186.  
  187.  
  188. Images and displays
  189.  
  190. In  image  processing we must distinguish  between  'images'  and 
  191. their  'displays'.  In  this context we define an  image  as  the 
  192. information  that  has  been  stored (as  1's  and  0's)  with  a 
  193. particular  filename  in the computer's memory or on  a  magnetic 
  194. disk. A display is the representation of such an image on a video 
  195. screen or -as a 'hardcopy'- on a piece of paper.
  196.  
  197. An important property of an image is its information content. The 
  198. information  in  an  image depends on  the  presence  of  details 
  199. (lines,   edges,   intensities,   colors,  etc.).  Moreover,  the 
  200. information  content  determines the amount  of  computer  memory 
  201. required to store the image.
  202.  
  203. Note that it's one thing to store an image accurately,  but  that 
  204. it's another to display it with full conservation of information!    
  205. The display hardware (video controller,  monitor,  printer, etc.) 
  206. determines the degree to which the information in an image can be 
  207. observed  exactly.  In image processing,  there is a tendency  to 
  208. make  the  information content of stored images higher  than  can 
  209. actually be displayed.  This reduces the chance that the  effects 
  210. of  rounding errors in intermediate results will deteriorate  the 
  211. final  display.  (Moreover,  RAM-chips and floppy disks are  much 
  212. cheaper  than  display hardware!).  AIM,  for  example,  uses  64 
  213. kilobytes  (kB)  of RAM for the storage of  images,  whereas  the 
  214. Atari  hardware  can  only handle 32 kB for the  display  of  one 
  215. screen (either monochrome or color).
  216.  
  217. The basic element of an image is a pixel (picture element). To be 
  218. observable on a display,  a pixel must be attributed a grey value 
  219. or color information.
  220.  
  221. As  an example,  consider the Atari ST.  In the monochrome  (high 
  222. resolution)  mode  the Atari ST supports the display  of  2  grey 
  223. values only.  Each pixel (the Atari screen has 640*400 =  256,000 
  224. of  them!)  has  a number ('0' or '1') associated  with  it  that 
  225. determines whether it is to be black or white:  there is  nothing 
  226. in between. We will call this a 'binary display'.
  227.  
  228. Note  that terms like 'black',  'white' and 'grey value'  in  the 
  229. context  of  monochrome  displays actually  refer  to  the  color 
  230. emitted by the phosphor used in the Cathode Ray Tube (CRT) of the 
  231. display device (amber, green, white, etc.).
  232.  
  233. Color  images generally consist of  three  sub-images,  displayed 
  234. simultaneously. The sub-images represent the decomposition of the 
  235. color  image into three monochrome images (red,  green and  blue, 
  236. respectively).  The (visual) addition of the sub-images  restores 
  237. the original colors for the observer.  Sub-images may be  binary, 
  238. but  usually they have more than two grey values.  An  AIM  color 
  239. image,  for example,  has 256 possible grey values for each  sub-
  240. image.
  241.  
  242. In the color modes (medium-,  resp.  low-resolution),  the ST  is 
  243. capable of displaying 8 grey values for all three primary colors. 
  244. Consequently,  there are 8*8*8 = 512 different combinations, each 
  245. combination representing another color. Such a group of available 
  246. colors is called a palette.  The palette represents all  possible 
  247. states that an individual pixel may have.
  248.  
  249. Each combination of red,  green and blue intensities is perceived 
  250. with   a  particular   brightness,   the   luminance.   Luminance 
  251. information  can  be used for the display of color  images  on  a 
  252. monochrome monitor; AIM allocates an extra sub-image for it.
  253.  
  254. If  a pixel has equal intensities for red,  green and blue  ,  it 
  255. will display the color 'grey'.  Thus,  in the palette of the med-
  256. res and lo-res color modes there are 8 levels of grey,  extending 
  257. from black (R=G=B=min=0) to white (R=G=B=max=7).  Very often  the 
  258. property of a color monitor to display grey values (as opposed to 
  259. just  black  or  white) is more important to the  user  than  its 
  260. capability of displaying colors!
  261.  
  262. As  we have seen above,  in binary images each pixel can  have  2 
  263. grey  values  only.  We say that each pixel has 1  'bit'  (binary 
  264. digit) of information associated with it.  Equivalently, in color 
  265. images the information per pixel is higher;  AIM uses 32 bits  of 
  266. color and grey value information. We will return to this shortly.
  267.  
  268.  
  269. Pixels and neighbors.
  270.  
  271. An  AIM image can be visualized as a 'checkerboard' with  256*256 
  272. or  128*128  square  fields (for  monochrome  and  color  images, 
  273. respectively).  Each field corresponds to a pixel carrying 8 bits 
  274. (= 1 Byte) of grey value information or 32 bits (= 3+1 Bytes)  of 
  275. color and luminance information.
  276.  
  277. Pixels,  being  neatly  arranged in a square raster of  rows  and 
  278. columns,  have neighbors. The number of neighbors of a particular 
  279. pixel  is  referred to as its  connectivity.  On  a  checkerboard 
  280. neighbors can be defined as having either just sides, or sides as 
  281. well as corners, in common with the reference pixel. Depending on 
  282. these  definitions the connectivity of pixels on a square  raster 
  283. is 4 or 8.  Pixels sometimes are arranged hexagonally.  In such a 
  284. 'honeycomb configuration' the connectivity is 6.
  285.  
  286. Image  processing  routines  can be divided  into  three  groups: 
  287. point,  local  and global operations.
  288.  
  289. Point  operations use the information of one single pixel in  the 
  290. input  image  to calculate the result for a  corresponding  pixel 
  291. (not necessarily the same) in the output image. An example is the 
  292. INVERT operation,  where the intensity bit for every pixel in the 
  293. (binary) image is reversed.
  294.  
  295. In  a  local  operation the result for one single  pixel  of  the 
  296. output  image  is  determined  by  the  original  pixel  and  its 
  297. neighborhood.  An  example of such an operation is  Lmin  ('Local 
  298. minimum'),  where the output pixel gets the minimum grey value of 
  299. its  neighborhood  (including itself) in the  input  image.  This 
  300. operation  extends dark parts in the image.  The neighborhood  of 
  301. interest can often be specified (i.e.  1*3,  3*3,  5*5, etc.). In 
  302. AIM the neighborhood can only be an odd number.
  303.  
  304. In  global operations the result for one single output  pixel  is 
  305. derived  from the information of all pixels in the  input  image. 
  306. One example of a global operation is the Fourier transform,  used 
  307. to determine periodic features in the image.  Fourier  transforms 
  308. are not supported in this version of AIM.
  309.  
  310. PROPERTIES OF THE ATARI ST VIDEO HARDWARE
  311.  
  312. Almost all of AIM's images will probably have to be displayed  on 
  313. a video monitor (either monochrome or color).  However perfect an 
  314. image may be,  it will eventually have to pass the bottleneck  of 
  315. the  computer's  video display hardware.  Much of the  effort  of 
  316. programming  AIM  has  been  devoted  to  overcoming   inevitable 
  317. limitations  of  a computer's display  hardware.  For  a  correct 
  318. interpretation of the results,  we will extend briefly into  some 
  319. details  of the hardware used by the Atari ST for the control  of 
  320. displays:  video display memory, video controller and monitors.
  321.  
  322.  
  323. The video display memory.
  324.  
  325. The  central  part of the display hardware is the  video  display 
  326. memory. Independent of the resolution chosen (lo-, med-, hi-res), 
  327. the Atari ST allocates 32 kB (= 256,000 bits) of RAM for  storage 
  328. of the information of one screen.
  329.  
  330. In  the  high  resolution mode 640*400 = 256,000  pixels  can  be 
  331. displayed,  leaving just one bit/pixel for grey value definition. 
  332. As  a result only binary images can be displayed on a  monochrome 
  333. monitor.
  334.  
  335. As  explained above,  a color image requires more than 1  bit  of 
  336. memory per pixel.  You may wonder how the ST manages to attribute 
  337. more  than 1 bit to a pixel if in the hi-res mode  (1  bit/pixel) 
  338. all the available 32 kB is used up already!
  339.  
  340. The  answer  to this question can be intuitively found  from  the 
  341. terms  'medium-resolution'  and 'low-resolution'  for  the  color 
  342. modes. In these modes, the spatial resolution of the hi-res mode, 
  343. 640*400  =  256,000 pixels,  is sacrificed in order to  give  the 
  344. pixels more luminance (monochrome displays on color monitors)  or 
  345. color  information.  By  reducing  the resolution  to  640*200  = 
  346. 128,000 (med-res) or 320*200 = 64,000 pixels (lo-res), the pixels 
  347. can be attributed 2 or 4 bits for luminance or color  definition. 
  348. This allows palettes of 4 or 16 colors to be defined in the  med-
  349. res or lo-res mode, respectively.
  350.  
  351. Thus, the video display memory may be thought of as representing:
  352.  
  353.           1 binary image  of 640*400 pixels (hi-res)
  354.           2 binary images of 640*200 pixels (med-res)
  355.           4 binary images of 320*200 pixels (lo-res).
  356.  
  357. The  color of a particular pixel is determined by the  (weighted) 
  358. bit-values of the 2/4 corresponding pixels in the binary images.
  359.  
  360. The video controller.
  361.  
  362. The next stop on our journey from the video display memory to the 
  363. monitor screen is the video controller.  This chip takes care  of 
  364. all the housekeeping, required for conversion of the bytes in the 
  365. video  display memory to 'real world' voltages,  compatible  with 
  366. the intensity input(s) of the monitors.
  367.  
  368. Since  in the hi-res mode the pixels contain just 1 bit  of  grey 
  369. value  information,  the  video controller  incorporates  a  very 
  370. simple 1 bit 'A/D converter' to generate the intensity signal for 
  371. the monochrome monitor.
  372.  
  373. We have seen that, as a consequence of the limited 32 kB of video 
  374. display  memory,  in the med-res and lo-res modes the pixels  can 
  375. have  just 2/4 bits of color information.  This would  allow  for 
  376. palettes of 4/16 colors.  Fortunately, Atari has made the ST much 
  377. more versatile,  generously including three 3 bit A/D  converters 
  378. in the video controller. Thus, for each primary color there are 8 
  379. grey values available, allowing a palette of 8*8*8 = 512 colors.
  380.  
  381. If  the  pixels contain information for the  definition  of  4/16 
  382. colors  only,  how does the video controller know what colors  to 
  383. choose  from the palette of 512?  The answer is in the  operating 
  384. system;  it  has  facilities to define a  'sub-palette'  of  4/16 
  385. colors.  Each  color in the sub-palette represents  a  particular 
  386. combination  of  grey values for red,  green  and  blue  .  These 
  387. combinations are stored in a lookup table of 4/16  elements.  The 
  388. 2/4 bit color information for each pixel refers to a position  in 
  389. this  lookup  table and the video controller  converts  the  RGB-
  390. combination stored there into the corresponding intensity control 
  391. voltages.
  392.  
  393. When  a color monitor is used to display a monochrome grey  value 
  394. image,  the operating system automatically loads the lookup table 
  395. with  4/8 (why not 16?) grey combinations for med-res  or  lo-res 
  396. displays, respectively.
  397.  
  398.  
  399. The monitors.
  400.  
  401. Basically, a video monitor consists of a CRT with some electronic 
  402. circuitry  to  control the deflection and the  intensity  of  the 
  403. electron  beam.  A monochrome monitor uses one electron  beam.  A 
  404. color monitor requires three beams, one for each primary color.
  405.  
  406. For  intensity  control  the monitors have 1  or  3  inputs.  The 
  407. voltage on these inputs determines the intensity of the lightspot 
  408. on  the  screen.
  409.  
  410. Note,  that  in principle both monochrome and color monitors  are 
  411. capable  of displaying grey values:  there is a continuous  range 
  412. over which the intensities can be controlled. However, as we have 
  413. seen,  the other display hardware reduces the number of  possible 
  414. grey values and/or colors considerably.
  415.  
  416. The  deflection  of  the electron beam(s) is  controlled  by  the 
  417. monitor itself;  for synchronization it needs a triggering signal 
  418. ('sync')  which  is produced by the video controller  and  simply 
  419. added to the intensity signal(s).
  420.  
  421.  
  422.  
  423. AIM IMAGES AND THEIR DISPLAY ON THE ATARI ST MONTORS
  424.  
  425. The AIM workspace allows simultaneous storage of 4 images:  A, B, 
  426. C  and  D.  Each image (monochrome or color) occupies  64  kB.  A 
  427. monochrome image (stored on disk with the extension .IM) consists 
  428. of 256*256 pixels,  having 8 bits of grey value information (i.e. 
  429. 256 grey values possible).  Color images (extension .COL) consist 
  430. of  128*128 pixels,  having 24+8=32 bits of color  and  luminance 
  431. information.  For  the display of color images AIM  supports  the 
  432. ST's  lo-res  mode  only (320*200 pixels with  a  palette  of  16 
  433. colors). 
  434.  
  435. You  may  have wondered why AIM uses 4 Bytes of  information  for 
  436. pixels  of  .COL  images.  Wouldn't a color  image  be  perfectly 
  437. defined by just using 1 Byte for each color sub-image? The answer 
  438. is: yes, it would. For technical reasons, however, we have chosen 
  439. to  add  en  extra byte for  luminance  definition.  This  format 
  440. allows, for example, the monochrome display of .COL images.
  441.  
  442. We  will  discuss  the  display of AIM  images  in   4  different 
  443. situations:
  444.  
  445.     Monochrome (.IM) images - monochrome display (hi-res)
  446.     Color (.COL) images     - monochrome display (hi-res)
  447.     Monochrome (.IM) images - color display (lo-res) 
  448.     Color (.COL) images     - color display (lo-res)
  449.  
  450.  
  451. Monochrome (.IM) images - monochrome display (hi-res).
  452.  
  453. As  an extension to our checkerboard model we might  introduce  a 
  454. stack of 8 checkers placed on each field, representing the 8 grey 
  455. value bits of the corresponding pixel. A white checker represents 
  456. a '1',  a black one a '0'. Depending on its position in the stack 
  457. the weight of a white checker (i.e.  the contribution to the grey 
  458. value) is 128, 64, 32, 16, 8, 4, 2 or 1. Thus, if the lower three 
  459. and  the  upper two checkers are white,  the  corresponding  grey 
  460. value is (128+64+32+0+0+0+2+1=) 227.
  461.  
  462. In  our  model we have 8 horizontal planes of  256*256  checkers, 
  463. each plane contributing its own weight to the total  image.  Note 
  464. that  each plane itself actually corresponds to a  binary  image, 
  465. hence  the name:  bitplanes.  The upper plane (b1) is  the  least 
  466. significant   bitplane,   the  lower  plane  (b8)  is  the   most 
  467. significant one. In AIM the 8 bitplanes of a grey value image can 
  468. be processed as 8 separate binary images.  Bitplanes of one image 
  469. can be copied (command:  BCOPY) to one or more arbitrarily chosen 
  470. bitplane(s) of an other.  Using this facility, a grey value image 
  471. can  be  used as a (temporary) storage for 8  independent  binary 
  472. images.
  473.  
  474. As determined by the ST hardware,  in the hi-res mode only binary  
  475. images can be displayed. AIM circumvents this limitation by using 
  476. a  trick  called  sigma-delta  technique:  the  256  grey  values 
  477. available in the image are represented as well as possible by dot 
  478. densities  in the display.  This yields a 256*256*1  bit  display 
  479. with a reasonable suggestion of grey values to the human eye.
  480.  
  481. A  special  situation  occurs if we want  to  process  monochrome 
  482. pictures  from  the  drawing  package  DEGAS.   Monochrome  DEGAS 
  483. pictures  (extension .PI3),  being binary 640*400  pixel  images, 
  484. cannot be processed directly by AIM.  When read from a disk these 
  485. images  are converted to a 320*200 pixel image with 5  levels  of 
  486. grey information.  The 640*400 pixels are grouped in 320*200 non-
  487. overlapping  2*2 fields.  Each pixel in the final  320*200  pixel 
  488. image  is attributed the average grey value of the  corresponding 
  489. 2*2 field:
  490.  
  491.                 0 pixels white  ->  grey value:   0
  492.                 1 pixels white  ->  grey value:  63
  493.                 2 pixels white  ->  grey value: 127
  494.                 3 pixels white  ->  grey value: 191
  495.                 4 pixels white  ->  grey value: 255
  496.  
  497. Subsequently, the converted DEGAS images get the same sigma-delta 
  498. treatment  as  the  regular .IM images for the  display  of  grey 
  499. values.  Note  that  in this process  information  is  lost;  the 
  500. resulting  image  has  less  than 320*200*3  =  192,000  bits  of 
  501. information (originally: 256,000 bits). Consequently, even though 
  502. AIM can re-convert (loosing information again!) these images back 
  503. to  DEGAS format,  the original pictures can never  be  recovered 
  504. completely.
  505.  
  506.  
  507. Color (.COL) images - monochrome display (hi-res).
  508.  
  509. For the display of a .COL image on a monochrome monitor, only the 
  510. 128*128  pixel  luminance  sub-image  is  used.  The  sigma-delta 
  511. technique  again  converts  this  luminance  information  to  dot 
  512. densities.
  513.  
  514.  
  515. Monochrome (.IM) images - color display (lo-res).
  516.  
  517. Monochrome  (.IM) images have 8 bits (256 levels) of  grey  value 
  518. information.  When an (.IM) image is read from disk in the lo-res 
  519. mode,  AIM  will load the 16 color palette with the maximum of  8 
  520. levels   of  grey  and  applies  the  sigma-delta  technique   to 
  521. interpolate between these 8 levels.
  522.  
  523.  
  524. Color (.COL) images - color display (lo-res).
  525.  
  526. For  the  display  of .COL images in the lo-res  mode  AIM  first 
  527. determines  an optimum palette of 16 colors from the  palette  of 
  528. 256*256*256 colors available in the original image. The 8 bits of 
  529. luminance information is not used.
  530.  
  531. The palette for a particular screen is derived from the image  in 
  532. the active window only;  this may not be the optimum palette  for 
  533. other images displayed simultaneously.
  534.  
  535. In this mode color pictures from the DEGAS and Neochrome  drawing 
  536. packages  (extensions .PI1 and .NEO,  resp.) can be read  by  AIM 
  537. also.  Again,  size  reduction (to 160*100  pixels),  grey  value 
  538. attribution  and  the sigma-delta technique are applied  for  the 
  539. processing and display of these images. 
  540.  
  541.  
  542. IMAGE PROCESSING CAPABILITIES OF AIM
  543.  
  544. The image processing software package AIM has been written in the 
  545. C  language,   using  the  Mark  Williams  C-compiler.  It  makes 
  546. extensive use of the GEM window structure for the user  interface 
  547. and the display of images.  AIM allows processing and display  of 
  548. monochrome,  binary  and  grey value images as well as  of  color 
  549. images.  It  has  an interface (via the Atari ST's  DMA  bus)  to 
  550. monochrome  and color frame grabbers,  developed in  the  Pattern 
  551. Recognition Group.
  552.  
  553.  
  554. The user interface.
  555.  
  556. Image processing operations can be chosen from drop-down  menues, 
  557. using dialog boxes,  as well as by typing the appropriate command 
  558. in the command box.  In any case the commands are transferred  as 
  559. strings   by  the  Window  Management  System  to   the   Command 
  560. Interpreter.  Many  of  the AIM commands cannot be  invoked  from 
  561. drop-down menues. They will be designated by an asterisk (*). 
  562.  
  563. The command interpreter starts the image processing  routine.  It 
  564. is not necessary to type the complete command name; any number of 
  565. characters that doesn't give ambiguities will do.
  566.  
  567. Sequences of commands may be combined in a command file or macro. 
  568. Command files can be nested to 16 levels.  They are automatically 
  569. created  by  activating the Logging feature;  any  operation  you 
  570. perform after 'Logging' is checked, will be logged. Macros can be 
  571. saved to disk for re-use. The extension for the filename is .AIM. 
  572. A  macro  is  executed by typing the  name  (without  extension), 
  573. preceded by the character '@'.  Clicking the menu-entry Macro and 
  574. the  name  in  the  dialog box will  do  the  same.  Pausing  the 
  575. execution  is possible by hitting the Esc-key.  Proceed with  the 
  576. macro  by hitting Return or stop by clicking in  the  appropriate 
  577. box.
  578.  
  579. The commands in the Command Window can be edited  simply.  Delete 
  580. and backspace work like in most wordprocessors. Control-X deletes 
  581. a whole line.
  582.  
  583. All  characters  typed after a star (*) will be  ignored  by  the 
  584. command interpreter and thus can be used for comments.
  585.  
  586. Typing  a question mark (?) and <Return> will display a  list  of 
  587. available operations.  The syntax and a short explanation for the 
  588. commands  can  be found in  Help-files.  Choose  HELP!!!  in  the 
  589. Utilities menu. Note, however, that this version (2.5) of AIM has 
  590. been  extensively revised.  Many operations have been  added  and 
  591. some  of  the  existing operations allow more  parameters  to  be 
  592. specified  than those given in the current Help-files and  dialog 
  593. boxes.  Fortunately,  all operations are upward compatible.   The 
  594. AIMANUAL.DOC   in  the  COMPRESS  folder  contains   an   updated 
  595. description of all the available operations. 
  596.  
  597.  
  598. EXAMPLES AND DEMOS
  599.  
  600. The  examples  on  the AIM disk  are  self-explaining.  The  only 
  601. prerequisite  is  a  reasonable  understanding  of  the  previous 
  602. chapters.  Because  the  disk space was limited,  we  could  only 
  603. include  some of the most relevant  examples.  Consequently  they 
  604. cover  just  a  few  of the  possible  operations;  most  of  the 
  605. operations will have to be explored by yourself!
  606.  
  607. The  commented  command files EXAM1.AIM ->  EXAM5.AIM  have  been 
  608. included so that you can check your manually entered exercises. 
  609.  
  610. Besides  the  prepared examples three extra demos  (macros)  have 
  611. been  included  on  the  disk:   DEMOCER.AIM,   DEMOHFE.AIM   and 
  612. DEMOSCH.AIM. They contain some operations and strategies that may 
  613. be  of  interest  to  you after  having  completed  the  examples 
  614. successfully.
  615.  
  616. Finally two exercises are added to (self-)test your abilities. If 
  617. things go totally wrong,  don't feel embarrassed by peeping  into 
  618. the  macros  PRAK1.AIM  and  PRAK2.AIM;   they  contain  possible 
  619. solutions for these exercises. The exercises are compressed files 
  620. and can be found in the folder COMPRESS.
  621.  
  622. In  case  you  missed a point:  in a  grey  value  image  'black' 
  623. corresponds with a value 0, 'white' with a value 255. In a binary 
  624. image  (or a bitplane of a grey value image) these values  are  0 
  625. and 1, respectively.
  626.  
  627. All examples and exercises will work in both modes,  lo-res color 
  628. and hi-res monochrome. For binary operations a monochrome monitor 
  629. is recommended. Some demos are more impressive in color, though!
  630.  
  631.  
  632. Example EXAM1.AIM
  633.  
  634. Operations used: Histogram, Equalize
  635.  
  636. First we will retrieve the image MOON.IM.  Click the entry  'Read 
  637. Image'  under the 'File' menu.  The defaults in the selector  box 
  638. that  pops up ('Window:  A' and 'STANDARD')  are  acceptable,  so 
  639. click  'OK' (or hit the Return key).  Those of you who  prefer  a 
  640. command  line interpreter might as well type in 'read A'  instead 
  641. of using the mouse.
  642.  
  643. Next a GEM 'ITEM SELECTOR' appears.  Choose 'MOON.IM' and after a 
  644. few seconds a picture appears in Window A,    that shows the foot 
  645. of  moonlander  surounded  by  moondust.  You  will  agree  that, 
  646. normally,  you  would  throw such a picture in the  trashcan  and 
  647. probably declare the mission to the moon a flop. AIM can help you 
  648. deal with such frustations!
  649.  
  650. Just  to get a feel of the power accumulated in that  tiny  3.5", 
  651. try the operation 'Equalize' under the menu 'GreyOps'.  Choose  A 
  652. as the input image and B as the output. Looks better, doesn't it? 
  653. Remember,  the information was already in the image; even without 
  654. AIM the mission to the moon wasn't in vain!  But the  application 
  655. of AIM certainly adds to the succes.
  656.  
  657. To  understand what has happened to the original image,  try  the 
  658. entry  'Histogram' under 'Utilities'.  This will show a graph  of 
  659. the  frequency  of  occurrence of a  particular  grey  value  (or 
  660. rather:  a  small  range of grey values) in  the  image,  plotted 
  661. against the grey value.  Frequencies are plotted vertically, grey 
  662. values (0 -> 255) horizontally.  The histogram indicates that the 
  663. grey  values  in  the  original  image  were  concentrated  in  a 
  664. relatively small range (centered around grey value 50).
  665.  
  666. From the histogram we can conclude that the grey scale from 0  to 
  667. 255 has not been used efficiently;  nearly all pixels have a grey 
  668. value between,  say,  25 and 75. The result is that, in a way, we 
  669. are looking at the printing on a toy balloon;  only if we inflate 
  670. the balloon some of the smaller details will show.  If somehow we 
  671. could  stretch the original grey value range,  so that  25  would 
  672. shift to 0 and 75 to 255, the same effect might be imposed on our 
  673. moon image. Throwing away the ranges 0 ->25 and 75 -> 255 doesn't 
  674. do much harm, because little information will be lost.
  675.  
  676. Equalization  is the air pump that inflates a grey  value  range. 
  677. Unlike   an  air  pump  (and  the  suggestion  in  the   previous 
  678. paragraph!)  it does so intelligently.  That is,  the  stretching 
  679. effect on a particular range of grey values depends on the height 
  680. of the histogram for that range.  Ranges with high values in  the 
  681. histogram will be expanded at the cost of the compression of less 
  682. prominent  ranges.  Note,  that there may be multiple  peaks  and 
  683. valleys  in the histogram.  To see what we  mean,  determine  the 
  684. histogram  of image B and compare it with the original  one.  The 
  685. frequencies  (vertical  lines) are divided more evenly  over  the 
  686. available range of grey values.
  687. Ranges  with  high  frequencies of  occurrence  in  the  original 
  688. histogram  have  been stretched and those  with  low  frequencies 
  689. compressed. If you are not completely satisfied, perform the same 
  690. operations on the image TRUI.IM,  which has multiple peaks in the 
  691. histogram.
  692.  
  693. Equalization  is a nice example of  image  processing:  important 
  694. features  (in this case grey value ranges) are emphasized at  the 
  695. cost  of  less  important  features.   Yet,  in  this  particular 
  696. operation no information is lost;  a 'de-emphasis' procedure (not 
  697. available in AIM) could restore the original image.
  698.  
  699. Hint:  if  you want to get rid of the histogram in  a  particular 
  700. display, use 'Gdisplay' in the Utilities menu.
  701.  
  702.  
  703. Example EXAM2.AIM
  704.  
  705. Operations: Gradx, Grady, Enhance
  706.  
  707. Read the image TRUI.IM in (the default) Window A.  This image has 
  708. become  a  kind of reference for many groups  involved  in  image 
  709. processing.
  710.  
  711. Perform the operation 'Gradx' in the GreyOps menu. Accept all the 
  712. defaults proposed by AIM. Worry about the Multiply and Add values 
  713. later, or better still, experiment with them.
  714.  
  715. The  Gradx ('gradient in x-direction') operation  determines  the 
  716. rate  at  which  grey values change in  the  original  image  and 
  717. attributes corresponding grey values to the pixels of the  output 
  718. image.  An  output  pixel  gets a grey  value  according  to  the 
  719. formula: 
  720.  
  721.        grey-out = (gradient-in) * Multiply/1024 + Add.
  722.  
  723. This  operation  shows  vertical edges  in  the  image.  An  edge 
  724. corresponds to a step in grey value.  Note the effect on edges in 
  725. the girl's hat.
  726.  
  727. Now perform Grady.  This time send the output to Window  C.  Note 
  728. the result for horizontal edges (mouth, eyebrows, etc.).
  729.  
  730. A  related  operation,  which  is generally  used  to  sharpen-up 
  731. pictures   is  the  Enhance-operation  (in  menu   GreyOps).   It 
  732. determines  the  second derivative (in both  directions)  of  the 
  733. grey-values in the input image.  Like Gradx/y it emphasizes  high 
  734. frequencies in the image.  High frequencies occur at sharp edges. 
  735. Try  the Enhance filter on the original TRUI.IM.  and  enjoy  the 
  736. improvement. But what did we do to her eyes? Seems we created her 
  737. contactlenses...
  738.  
  739.  
  740. Example EXAM3.AIM
  741.  
  742. Operation: Median filter
  743.  
  744. Read image BNOISE.IM.  This image has intentionally been degraded 
  745. by  'shot  noise'.  This  type  of  noise  occurs  often  in  the 
  746. transmission of signals.  Some of the pixels differ very much  in 
  747. grey  value from the surrounding pixels.  In this case  they  are 
  748. white. We want to use filtering to remove the noise.
  749.  
  750. Usually  it  is difficult to predict the  effects  of  filtering. 
  751. Various parameters must be specified,  requiring much  intuition. 
  752. Try, for example the entry 'Filter' in the GreyOps menu!
  753.  
  754. A  good  filter for the problem of shot noise  is  the  so-called 
  755. median filter.  In this operation AIM determines the grey  values 
  756. in  3*3 neighborhoods for each pixel in the  input  image.  These 
  757. values are sorted in tables with 9 entries. The 5th entry in each 
  758. table (the 'median') becomes the grey value of the  corresponding 
  759. output pixel.  The grey value of a shot noise speck is likely  to 
  760. be in the extremes of the tables in which it appears, and thus it 
  761. will be removed.
  762.  
  763. Perform  the operation 'Median' in the GreyOps menu.  Only a  few 
  764. stubborn  noise  specks will survive.  They may be removed  by  a 
  765. repeated application of this filter.
  766.  
  767.  
  768. Example EXAM4.AIM
  769.  
  770. Operations: Copy, Lmin, Lmax, (*)mindev, Gdisplay
  771.  
  772. Once more we call on TRUI.IM;  read it from disk.  We will need a 
  773. second copy of this image in Window B. There are two options:
  774. a. Read the image again from disk and have AIM put it in Window B
  775. b. Use 'Copy' in menu GreyOps to copy Window A in Window B.
  776.  
  777. Note  that there is a 'Copy' entry in the BinOps menu  too.  This 
  778. binary  operation  copies only bitplanes,  as opposed to  a  grey 
  779. value copy,  which copies all 8 bitplanes of an image at once.
  780.  
  781. If all went well, you now have the fabulous Trui twins on screen. 
  782. The  first  operation to be performed is 'Lmin'  in  the  GreyOps 
  783. menu.  This  operation looks for the lowest grey value in an  n*n 
  784. neighborhood  (n to be specified by the user) of the input  pixel 
  785. and attributes it to the corresponding output pixel.  This filter 
  786. has  a tendency of expanding darker areas in the  image.  Try  it 
  787. with n=9 and put the result in Window C. Experiment a little with 
  788. different values for n. Observe the effects on nostrils and eyes! 
  789. In  any case end with a 9*9 Lmin-ned TRUI.IM in  Window  C.
  790.  
  791. Next apply the 'Lmax' filter on Window A.  Choose n=9 and put the 
  792. result  in Window D.  This filter expands lighter area's  in  the 
  793. image. We hope that until now you acquired enough intuition to be 
  794. able to predict the effect:  gone are those nostrils and gone  is 
  795. that mouth in the 'lighter shade of pale' that surrounded them.
  796.  
  797. But now the real image processor arises.  We are going to use  an 
  798. operation  that uses three input images:  (*)mindev  C,D,A.  This 
  799. operation  compares corresponding pixels (i.e.  pixels  with  the 
  800. same  coordinates)  in the original image (A) and the  two  other 
  801. images  (C and D).  The output pixel gets the grey value  of  the 
  802. corresponding pixel in C or D,  depending on which one of the two 
  803. is  closest to the grey value in A.  Big deal,  but what  is  the 
  804. effect?
  805.  
  806. Let's  try  it  first.    The  (*)mindev  ('minimal   deviation') 
  807. operation cannot be invoked from the menu,  so we have to type it 
  808. in de Command Window: type mindev C,D,A <Return>. The result will 
  809. be shown in Window A.  Compare it with the original image,  which 
  810. is  still luring in Window B.  Apparently the edges in the  image 
  811. (cheeks,  hair) have been sharpened. The net effect of Lmin, Lmax 
  812. and mindev is, that near edges there is a backlash in grey value. 
  813. In  other  words,  grey  values are  reluctant  against  changes; 
  814. changes occur suddenly as a function of position.
  815.  
  816.  
  817. Example EXAM5.AIM
  818.  
  819. Operations:  (*)Clear,  Threshold, Invert, Propagation, Bdisplay, 
  820. Reset, Exor and (*) Measure.
  821.  
  822. Read the image CERMET.IM from disk.
  823.  
  824. Our  purpose with this example is to do some measurements on  the 
  825. objects  in this image.  The '(*)Measure' operation requires  the 
  826. objects  of interest to be white in a black  background.  In  the 
  827. menu  'BinOps' we have some useful operations at our disposal  to 
  828. achieve that goal.
  829.  
  830. In  order to be able to apply binary  operations  ('BinOps'),  we 
  831. first  will  make the grey value image in Window  A  binary.  The 
  832. operation  'Threshold'  in the GreyOps menu makes pixels  with  a 
  833. grey value below the threshold black and pixels with a grey value 
  834. above  it white.  When the operation is invoked,  it  proposes  a 
  835. threshold which is the average grey value in the image; it is not 
  836. necessarily  the best guess,  but usually it yields  satisfactory 
  837. results.
  838.  
  839. Stop! The Threshold operation will ask for the bitplane where the 
  840. binary  image  is to be stored (it defaults to b1 in  Window  B). 
  841. However, as our previous exercises will have left some garbage in 
  842. the  other bitplanes of Window B,  we first have to clear  those. 
  843. The operation '(*)Clear' is provided to clear all bitplanes of  a 
  844. window  at once (clear = grey value 0 = black!).  Type:  clear  B 
  845. <Return>.
  846.  
  847. Now we are ready for the Threshold operation;  click on it in the 
  848. GreyOps menu and accept the defaults.
  849.  
  850. As  we need white objects in a black background,  the picture  in 
  851. Window B must be inverted.  Click on 'Invert' in the BinOps  menu 
  852. (accept the defaults).
  853.  
  854. Note  that some of the objects near the frame of the  window  are 
  855. only  partially  displayed.   We  don't  want  the   '(*)Measure' 
  856. operation to take these incomplete objects into account,  but how 
  857. can  we  get  rid of them?  How can  we  distinghuish  them  from 
  858. complete objects? The answer is: use the 'Propagation'  operation 
  859. (in CelOps) .
  860.  
  861. The 'Propagation' operation allows us to isolate  objects.  White 
  862. pixels  (called 'seeds) will 'grow' (expand) under the  condition 
  863. that in a given reference bitplane (the 'mask') the corresponding 
  864. pixels are white too.  We can visualize this operation as  taking 
  865. place in a field with seeds (= white pixels that we want to  grow 
  866. to  shapes  present in the mask).  The  reference  bitplane  (the 
  867. 'mask')  is  the culture medium;  it has  fertile  and  infertile 
  868. regions.  If a region is fertile (i.e.  it has white pixels  that 
  869. coincide  with  the  seed pixels),  the seed  can  grow.  In  one 
  870. 'iteration'  (propagation step) a pixel grows in accordance  with 
  871. its  connectivity:  one  white pixel is added in  all  connecting 
  872. directions.  In  AIM  the seed bitplane is called  CLP  (Cellular 
  873. Logic Plane).
  874.  
  875. In the next iteration the seed bitplane (CLP) that resulted  from 
  876. the first iteration is compared once more with the mask bitplane. 
  877. Coinciding white pixels in CLP and mask will,  once  more,  grow. 
  878. This will continue until all seeds have grown to the edges of the 
  879. fields  in  the mask;  we have created an exact copy of  all  the 
  880. fields  that in the first iteration coincided with at  least  one 
  881. seed.  The trick of isolating particular fields in the mask is to 
  882. create a CLP with seeds that coincide with those fields.
  883.  
  884. Let's  return  to our problem of isolating the  incomplete  white 
  885. objects  at the borders of bitplane b1 in Window B.  It would  be 
  886. nice if we had a bitplane available (to be used as the CLP)  with  
  887. white  pixels  along the frame only.  The  Propagation  operation 
  888. would  make those border-pixels grow to the exact shapes  of  the 
  889. intersected  objects in the mask (in our case:  b1).  The  result 
  890. would  be:  two  images having the unwanted  objects  in  common. 
  891. Subsequent  application of the logical operation 'Exor'  (in  the 
  892. BinOps menu) on these two images will finally remove the unwanted 
  893. objects.   Exor   is  the  inequality   operator:   it   compares 
  894. corresponding pixels in both (binary!) images and outputs a white 
  895. pixel if (and only if) they are different. 
  896.  
  897. Now  that  we hopefully understand it we cannot wait to  put  our 
  898. knowledge to the test.  The only image we need is bitplane b1  in 
  899. Window B. Click on Propagation. We will have to change almost all 
  900. of the defaults!  Our mask bitplane is b1 instead of the proposed 
  901. b2.  Furthermore,  we will use b2 as our CLP instead of  b1.  The 
  902. connectivity is not important,  but change it to 8. The necessary 
  903. white edge for our CLP can be chosen with the entry 'Edge value'. 
  904. Choose 1 (for white).  Make the number of iterations 100; that is 
  905. too  many,  but AIM will stop automatically when all  growth  has 
  906. stopped. 
  907.  
  908. Check all entries in the Dialog Box:  if something is wrong there 
  909. is  a risk that you have to start all over again!  Your ST  won't 
  910. complain,  but  we  don't  want to  frustrate  prospective  image 
  911. processors in such an early stage.
  912.  
  913. Hit Return.  If all is well, you will see an image in bitplane b2 
  914. of Window B that has the intersected objects only.  Wrong?  Don't 
  915. worry,  just keep trying. Don't forget to clear bitplane b2 prior 
  916. to every Propagation operation.
  917.  
  918. Next invoke operation Exor (in BinOps). Use b1 and b2 in Window B 
  919. as inputs and b3 as output.
  920.  
  921. At  last our image is ready for the  (*)Measure  operation.  This 
  922. operation assumes that the image is in b1 of Window B, so we must 
  923. copy  b3  to  b1 first.  Click 'Copy' in BinOps  and  choose  the 
  924. appropriate bitplanes.
  925.  
  926. (*)Measure  performs a number of measurements on the objects  and 
  927. displays the results in the Command Window. It assigns numbers to 
  928. the  objects (left -> right,  up -> down) and labels each  object 
  929. with a grey value according to this number.  This can be observed 
  930. in Window D.
  931.  
  932. Type  measure  (mea will do!) <Return>.  Note  that  the  Command 
  933. Window can be sized to bring all measured data on screen. 
  934.  
  935.  
  936. PRACTICAL EXERCISES
  937.  
  938. PRAK1.
  939. Study the image PRAK1.IM. Your assignment is to separate the nuts 
  940. from the bolts.  In other words:  use AIM to generate two images, 
  941. one  containing  the nuts (including the one that  rests  on  its 
  942. side!) and the other one the bolts. Count the objects afterwards.
  943.  
  944. PRAK2.
  945. The image PRAK2.IM shows a handful of electronic components.  Try 
  946. to separate them. Use your fantasy and surprise husbands, friends 
  947. and neighbors!
  948.  
  949.